import { customRef } from "vue";
export default function useMsgRef(initValue: string, delay: number) {
  let timer: ReturnType<typeof setTimeout>
  let msg = customRef((track, trigger) => {
    return {
      get() {
        track()  //对msg进行持续追踪，一旦msg发生变化就更新
        return initValue
      },
      set(value) {
        clearTimeout(timer)
        timer = setTimeout(() => {
          initValue = value
          trigger()  //告诉vue msg发生变化了
        }, delay)
      }
    }
  })
  return { msg }
}